import request from '../utils/request'

// 获取用户选择的频道
const getUserChannelListAPI = () => request({
  url: '/v1_0/user/channels'
})

// 首页获取文章列表
// timestamp = Date.now() + '' 给timestamp时间戳设置一个默认值为当前的时间戳
// date.now() 获取当前事件的时间戳
const getArticleListAPI = ({ channelId, timestamp = Date.now() + '' }) => request({
  method: 'GET',
  url: '/v1_0/articles',
  params: {
    channel_id: channelId,
    timestamp
  }
})

// 首页文章不感兴趣
const articleDislikeAPI = ({ artId }) => request({
  method: 'POST',
  url: '/v1_0/article/dislikes',
  data: {
    target: artId
  }
})

// 文章举报
const articleReportsAPI = ({ artId, type, remark }) => request({
  method: 'POST',
  url: '/v1_0/article/reports',
  data: {
    target: artId,
    type,
    remark: type === '0' ? remark : remark || null
  }
})

// 获取所有频道
const getAllChannelAPI = () => request({
  method: 'GET',
  url: '/v1_0/channels'
})

// 更新用户选择频道
const updateChannelList = ({ channels }) => request({
  method: 'PUT', // 全局修改
  url: '/v1_0/user/channels',
  data: {
    channels
  }

})
export {
  getUserChannelListAPI,
  getArticleListAPI,
  articleDislikeAPI,
  articleReportsAPI,
  getAllChannelAPI,
  updateChannelList
}
